package com.zy.dao.impl;

import com.zy.bean.MUsers;
import com.zy.dao.IUserDao;
import com.zy.utils.DbUtil;

import java.sql.*;

public class UserDao implements IUserDao {

    @Override
    public String insertUser(MUsers musers) {
        return null;
    }

    @Override
    public MUsers queryUser(MUsers musers) throws SQLException, ClassNotFoundException {
        MUsers  mUsersTemp = null;
        Connection connection = DbUtil.getConnection();
        //预编译
        PreparedStatement ptmt = connection.prepareStatement("SELECT * FROM m_users where userName=? and password = ?"); //预编译SQL，减少sql执行
        ptmt.setString(1,musers.getUserName());
        ptmt.setString(2,musers.getPassword());
        ResultSet rs = ptmt.executeQuery();
        while(rs.next()){
            mUsersTemp = new MUsers();
            mUsersTemp.setuId(rs.getLong("uId"));
            mUsersTemp.setUserName(rs.getString("userName"));
            mUsersTemp.setPassword(rs.getString("password"));
            mUsersTemp.setStatus(rs.getInt("status"));
            mUsersTemp.setCreateUser(rs.getString("createUser"));
            mUsersTemp.setCreateTime(rs.getDate("createTime"));
            System.out.println(rs.getString("userName")+" pas："+rs.getString("password"));
        }
        return mUsersTemp;
    }

    @Override
    public String updateUser(MUsers musers) {
        return null;
    }
}
